﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Starbucks.Messages;
using System.Diagnostics;
using PServiceBus.MessageProxy;

namespace Starbucks {
    class Program {
        
        static void Main(string[] args) {

            ProxyService.Start();

            var service = ProxyService.Create<IStarbuckService>();

            service.ReceiveDrinkReady(msg =>
            {
                Console.WriteLine("{0} drink is ready", msg.CustomerName);
                Console.WriteLine("\r\nType drink name to order");
            }, ex => true);

            service.ReceiveDrinkPayment(msg => {
                Console.WriteLine("Payment was made by {0} for amount of ${1:0.00}", msg.CustomerName, msg.Amount);
                service.SendDrinkPaymentMade(new DrinkPaymentMade() { CustomerName = msg.CustomerName });
            }, ex => true);

            service.ReceiveNewDrinkOrderAccepted(
                msg => Console.WriteLine("Yay, order has been accepted for {0}", msg.CustomerName),
                ex => true);

            Console.WriteLine("Welcome to Starbucks... Type exit to leave starbucks after making order");
            Console.WriteLine("Type drink name to order");
            while (true) {
                var drinkName = Console.ReadLine();
                if (drinkName.ToLower() == "exit") break;
                service.SendNewDrinkOrder(
                    new NewDrinkOrder() { 
                        Name = drinkName, CustomerName = "TJ", Type = DrinkType.Large });
            }
            
            ProxyService.Shutdown();
        }
    }
}
